from hashlib import md5
from app.settings.base import signatureKey


class Signature(object):
    def __init__(self):
        self.key = signatureKey

    def getSign(self, srcData):
        srcData = f'{srcData}:{self.key}'
        bodymd5 = md5(srcData.encode('utf-8')).hexdigest()
        return bodymd5.lower()

    def verifySign(self, revSign, revData):
        if revData is None:
            revData = b''
        # revData = revData.decode().replace('\n', '').replace('\r', '').replace(' ', '').replace('\t', '')
        signData = self.getSign(revData)
        if revSign.lower() != signData:
            return False, signData
        return True, signData
